package yyee.llee.mmee.weather.repository

import yyee.llee.mmee.base_api_net.base_api_bean.WeatherHour
import yyee.llee.mmee.base_api_net.base_api_bean.bean.BaseResult
import yyee.llee.mmee.base_api_net.base_api_bean.bean.CalendarBean
import yyee.llee.mmee.base_api_net.base_api_bean.bean.GuideToLifeBean
import yyee.llee.mmee.base_api_net.base_api_bean.bean.ResAlarmBean
import yyee.llee.mmee.base_api_net.base_api_bean.bean.ToadyWeatherBean
import yyee.llee.mmee.weather.base.BaseRepository
import com.ultra.kingclean.cleanmore.bean.ReqWarningBean
import com.ultra.kingclean.cleanmore.bean.ReqWeatherBean

/**
 * Created by Lingbaeryi
 */
class WeatherRepository : BaseRepository() {

    suspend fun getWeatherNow(city: String): BaseResult<ToadyWeatherBean> {
        return safeApiCall(call = { requestWeatherNow(city) }, errorMessage = "网络错误")
    }

    private suspend fun requestWeatherNow(city: String): BaseResult<ToadyWeatherBean> {
        return executeResponseForJH(mApiManager.getWeatherNow(city))
    }

    suspend fun getSuggestion(city: String): BaseResult<GuideToLifeBean> {
        return safeApiCall(call = { requestSuggestion(city) }, errorMessage = "网络错误")
    }

    private suspend fun requestSuggestion(city: String): BaseResult<GuideToLifeBean> {
        return executeResponseForJH(mApiManager.getSuggestion(city))
    }


    suspend fun getCalendar(date: String): BaseResult<CalendarBean> {
        return safeApiCall(call = { requestCalendar(date) }, errorMessage = "网络错误")
    }

    private suspend fun requestCalendar(date: String): BaseResult<CalendarBean> {
        return executeResponse(mApiManager.requestCalendar(date))
    }

    private suspend fun requestWeatherHour(reqWeatherBean: ReqWeatherBean): BaseResult<WeatherHour> {
        return executeResponse(mApiManager.requestWeatherHour(reqWeatherBean))
    }


    private suspend fun reqAlarm(reqWarningBean: ReqWarningBean): BaseResult<ResAlarmBean> {
        return executeResponse(mApiManager.getAlarm(reqWarningBean))
    }

}